home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / tcpdump-3.0.2 / print-null.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-11  |  2.7 KB  |  112 lines

  1. /*
  2.  * Copyright (c) 1991, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#)$Header: print-null.c,v 1.14 94/06/10 17:01:35 mccanne Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/time.h>
  29. #include <sys/socket.h>
  30. #include <sys/file.h>
  31. #include <sys/ioctl.h>
  32.  
  33. #include <net/if.h>
  34.  
  35. #include <netinet/in.h>
  36. #include <netinet/in_systm.h>
  37. #include <netinet/ip.h>
  38. #include <netinet/if_ether.h>
  39. #include <netinet/ip_var.h>
  40. #include <netinet/udp.h>
  41. #include <netinet/udp_var.h>
  42. #include <netinet/tcp.h>
  43. #include <netinet/tcpip.h>
  44.  
  45.  
  46. #include <stdio.h>
  47.  
  48. #include "interface.h"
  49. #include "addrtoname.h"
  50. #include "pcap.h"
  51.  
  52. #define    NULL_HDRLEN 4
  53.  
  54. static void
  55. null_print(const u_char *p, const struct ip *ip, int length)
  56. {
  57.     u_int family;
  58.  
  59.     bcopy(p, &family, sizeof(family));
  60.  
  61.     if (nflag) {
  62.         /* XXX just dump the header */
  63.         return;
  64.     }
  65.     switch (family) {
  66.  
  67.     case AF_INET:
  68.         printf("ip: ");
  69.         break;
  70.  
  71.     case AF_NS:
  72.         printf("ns: ");
  73.         break;
  74.  
  75.     default:
  76.         printf("AF %d: ", family);
  77.         break;
  78.     }
  79. }
  80.  
  81. void
  82. null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
  83. {
  84.     int length = h->len;
  85.     int caplen = h->caplen;
  86.     const struct ip *ip;
  87.  
  88.     ts_print(&h->ts);
  89.  
  90.     /*
  91.      * Some printers want to get back at the link level addresses,
  92.      * and/or check that they're not walking off the end of the packet.
  93.      * Rather than pass them all the way down, we set these globals.
  94.      */
  95.     packetp = p;
  96.     snapend = p + caplen;
  97.  
  98.     length -= NULL_HDRLEN;
  99.  
  100.     ip = (struct ip *)(p + NULL_HDRLEN);
  101.  
  102.     if (eflag)
  103.         null_print(p, ip, length);
  104.  
  105.     ip_print((const u_char *)ip, length);
  106.  
  107.     if (xflag)
  108.         default_print((const u_char *)ip, caplen - NULL_HDRLEN);
  109.     putchar('\n');
  110. }
  111.  
  112.